//
//  MyNodeVC.m
//  digitalCurrency
//
//  Created by 小震GG on 2019/11/1.
//  Copyright © 2019 XinHuoKeJi. All rights reserved.
//
#import "MyNodeVC.h"
#import "MyNodeShenVC.h"
#import "MyNodeKuanVC.h"
#import "NewAllNetManager.h"

@interface MyNodeVC ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *logoImage;
@property (nonatomic, strong) UILabel *bianHaoLB;
@property (nonatomic, strong) UIImageView *rightImage;
@property (nonatomic, strong) UILabel *shouYiLB;

@property (nonatomic, strong) UILabel *shenCountLB;
@property (nonatomic, strong) UILabel *kuanCountLB;
@property (nonatomic, strong) UILabel *shenPriceLB;
@property (nonatomic, strong) UILabel *kuanPriceLB;
@property (nonatomic, strong) UILabel *zongPriceLB;

@end

@implementation MyNodeVC

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    if ([[UserDefault getString:tNode] isEqualToString:@"1"] && [[UserDefault getString:tNodeOnece] isEqualToString:@"0"]) {
        [UserDefault setString:tNodeOnece value:@"1"];
        [self setView];
        [self loadNodeInfo];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationController setNavigationBarHidden:NO animated:NO];

    self.viewTitle.text = LocalizationKey(@"我的节点");
    
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:LocalizationKey(@"矿机记录") style:UIBarButtonItemStylePlain target:self action:@selector(rightBtnAct)];
       self.navigationItem.rightBarButtonItem = rightBarItem;
       rightBarItem.tintColor = [UIColor whiteColor];
    
    [self setView];
    [self loadNodeInfo];
}

- (void)rightBtnAct{
   
}

- (void)loadNodeInfo{
    [NewAllNetManager myNodeCompleteHandle:^(id  _Nonnull resPonseObj, int code) {
        if (code) {
            NSInteger codeInt = [resPonseObj[@"code"] intValue];
            if (codeInt == 0) {
                NSDictionary *dataDic = resPonseObj[@"data"];
                self.bianHaoLB.text = [NSString stringWithFormat:@"%@%@",LocalizationKey(@"矿机编号"),dataDic[@"nodeNum"]];
                self.shouYiLB.text = [NSString stringWithFormat:@"%@",dataDic[@"nodeCode"]];
                
                self.shenCountLB.text = [NSString stringWithFormat:@"%@",dataDic[@"countDepth"]];
                self.kuanCountLB.text = [NSString stringWithFormat:@"%@",dataDic[@"countWidth"]];
                self.shenPriceLB.text = [NSString stringWithFormat:@"%@",dataDic[@"depthAmount"]];
                self.kuanPriceLB.text = [NSString stringWithFormat:@"%@",dataDic[@"widthAmount"]];
                self.zongPriceLB.text = [NSString stringWithFormat:@"%@",dataDic[@"nodeAmount"]];

            }
        }
    }];
}

- (void)setView{
    
    [self.bgView removeFromSuperview];
    self.bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWindowW, kWindowH)];
    [self.view addSubview:self.bgView];
    
    UILabel *titleLB = [[UILabel alloc]init];
    [self.view addSubview:titleLB];
    [titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(20);
        make.top.equalTo(24);
    }];
    titleLB.text = LocalizationKey(@"节点编号");
    titleLB.font = kFont(16);
    titleLB.textColor = tThreeColor;
    
    
    if ([[UserDefault getString:tNode] isEqualToString:@"0"]) {
        UIButton *jinShengBtn = [[UIButton alloc]init];
        [self.view addSubview:jinShengBtn];
        [jinShengBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(-20);
            make.top.equalTo(24);
            make.height.equalTo(22);
        }];
        [jinShengBtn setTitle:[NSString stringWithFormat:@"   %@   ",LocalizationKey(@"竞升节点")] forState:UIControlStateNormal];
        [jinShengBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        jinShengBtn.titleLabel.font = kFont(12);
        jinShengBtn.backgroundColor = [UIColor colorWithHEX:maincolor];
        jinShengBtn.layer.masksToBounds = YES;
        jinShengBtn.layer.cornerRadius = 11.0;
        [jinShengBtn addTarget:self action:@selector(jinShengBtnAct) forControlEvents:UIControlEventTouchUpInside];
    }
    
    UIView *headView = [[UIView alloc]init];
    [self.view addSubview:headView];
    [headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(20);
        make.right.equalTo(-20);
        make.top.equalTo(titleLB.mas_bottom).offset(15);
        make.height.equalTo(64);
    }];
    headView.backgroundColor = tMainColor;
    headView.layer.masksToBounds = YES;
    headView.layer.cornerRadius = 5.0;
    
    if ([[UserDefault getString:tNode] isEqualToString:@"0"]) {
        UILabel *noteLB = [[UILabel alloc]init];
        [headView addSubview:noteLB];
        [noteLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(0);
        }];
        noteLB.textColor = [UIColor whiteColor];
        noteLB.font = kFont(14);
        noteLB.text = LocalizationKey(@"未竞升节点");
        
        UILabel *noteLB1 = [[UILabel alloc]init];
        [self.view addSubview:noteLB1];
        [noteLB1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(20);
            make.right.equalTo(-20);
            make.top.equalTo(headView.mas_bottom).offset(20);
        }];
        noteLB1.textColor = tThreeColor;
        noteLB1.numberOfLines = 0;
        noteLB1.font = kFont(13);
        noteLB1.text = LocalizationKey(@"注：在竞升节点的时候，建议填写上级节点的邀请码。\n如果没有填写，则默认自己为根节点。\n竞升节点每个钱包只能操作一次，请慎重填写。");
    }
    else {
        self.logoImage = [[UIImageView alloc]init];
        [headView addSubview:self.logoImage];
        [self.logoImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(15);
            make.centerY.equalTo(0);
            make.width.height.equalTo(40);
        }];
        self.logoImage.hidden = YES;
        
        self.bianHaoLB = [[UILabel alloc]init];
        [headView addSubview:self.bianHaoLB];
        [self.bianHaoLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(20);
            make.centerY.equalTo(0);
        }];
        self.bianHaoLB.textColor = [UIColor whiteColor];
        self.bianHaoLB.font = kFont(14);
        
        self.rightImage = [[UIImageView alloc]init];
        [headView addSubview:self.rightImage];
        [self.rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(-150);
            make.centerY.equalTo(0);
            make.width.height.equalTo(40);
        }];
        self.rightImage.hidden = YES;
        
        self.shouYiLB = [[UILabel alloc]init];
        [headView addSubview:self.shouYiLB];
        [self.shouYiLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(-20);
            make.centerY.equalTo(0);
             }];
        self.shouYiLB.textColor = [UIColor whiteColor];
        self.shouYiLB.font = kFont(14);
        
        self.logoImage.image = ImageName(@"");
        self.bianHaoLB.text = LocalizationKey(@"矿机编号");
        self.rightImage.image = ImageName(@"");
        self.shouYiLB.text = LocalizationKey(@"节点邀请码");
        
        UILabel *titleLB1 = [[UILabel alloc]init];
        [self.view addSubview:titleLB1];
        [titleLB1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(20);
            make.top.equalTo(headView.mas_bottom).offset(30);
        }];
        titleLB1.textColor = [UIColor colorWithHEX:@"#9FB0BD"];
        titleLB1.font = kFont(14);
        titleLB1.text = LocalizationKey(@"纬度");
        
        UILabel *titleLB2 = [[UILabel alloc]init];
        [self.view addSubview:titleLB2];
        [titleLB2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(0);
            make.top.equalTo(headView.mas_bottom).offset(30);
        }];
        titleLB2.textColor = [UIColor colorWithHEX:@"#9FB0BD"];
        titleLB2.font = kFont(14);
        titleLB2.text = LocalizationKey(@"节点数");

        UILabel *titleLB3 = [[UILabel alloc]init];
        [self.view addSubview:titleLB3];
        [titleLB3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(-20);
            make.top.equalTo(headView.mas_bottom).offset(30);
        }];
        titleLB3.textColor = [UIColor colorWithHEX:@"#9FB0BD"];
        titleLB3.font = kFont(14);
        titleLB3.text = LocalizationKey(@"业绩(USDT)");
        
        UIView *contentView = [[UIView alloc]init];
        [self.view addSubview:contentView];
        [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(12);
            make.right.equalTo(-12);
            make.top.equalTo(titleLB1.mas_bottom).offset(10);
            make.height.equalTo(125);
        }];
        contentView.backgroundColor = tBgQianColor;
        
        UILabel *shenLB = [[UILabel alloc]init];
        [contentView addSubview:shenLB];
        [shenLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(9);
            make.top.equalTo(20);
        }];
        shenLB.textColor = tThreeColor;
        shenLB.font = kFont(12);
        shenLB.text = LocalizationKey(@"深度");
        
        UILabel *kuanLB = [[UILabel alloc]init];
           [contentView addSubview:kuanLB];
           [kuanLB mas_makeConstraints:^(MASConstraintMaker *make) {
               make.left.equalTo(9);
               make.top.equalTo(shenLB.mas_bottom).offset(20);
           }];
           kuanLB.textColor = tThreeColor;
           kuanLB.font = kFont(12);
           kuanLB.text = LocalizationKey(@"宽度");

        UILabel *zongLB = [[UILabel alloc]init];
           [contentView addSubview:zongLB];
           [zongLB mas_makeConstraints:^(MASConstraintMaker *make) {
               make.left.equalTo(9);
               make.top.equalTo(kuanLB.mas_bottom).offset(20);
           }];
           zongLB.textColor = tThreeColor;
           zongLB.font = kFont(12);
           zongLB.text = LocalizationKey(@"节点总业绩");
        
        self.shenCountLB = [[UILabel alloc]init];
        [contentView addSubview:self.shenCountLB];
        [self.shenCountLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(0);
            make.centerY.equalTo(shenLB);
        }];
        self.shenCountLB.textColor = tThreeColor;
        self.shenCountLB.font = kFont(12);
        self.shenCountLB.text = @"0";
        
        self.kuanCountLB = [[UILabel alloc]init];
        [contentView addSubview:self.kuanCountLB];
        [self.kuanCountLB mas_makeConstraints:^(MASConstraintMaker *make) {
                  make.centerX.equalTo(0);
                  make.centerY.equalTo(kuanLB);
        }];
        self.kuanCountLB.textColor = tThreeColor;
        self.kuanCountLB.font = kFont(12);
        self.kuanCountLB.text = @"0";
        
        self.shenPriceLB = [[UILabel alloc]init];
           [contentView addSubview:self.shenPriceLB];
           [self.shenPriceLB mas_makeConstraints:^(MASConstraintMaker *make) {
               make.right.equalTo(-9);
               make.centerY.equalTo(shenLB);
           }];
           self.shenPriceLB.textColor = tThreeColor;
           self.shenPriceLB.font = kFont(12);
           self.shenPriceLB.text = @"0";
        
        self.kuanPriceLB = [[UILabel alloc]init];
        [contentView addSubview:self.kuanPriceLB];
        [self.kuanPriceLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(-9);
            make.centerY.equalTo(kuanLB);
        }];
        self.kuanPriceLB.textColor = tThreeColor;
        self.kuanPriceLB.font = kFont(12);
        self.kuanPriceLB.text = @"0";
        
        self.zongPriceLB = [[UILabel alloc]init];
        [contentView addSubview:self.zongPriceLB];
        [self.zongPriceLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(-9);
            make.centerY.equalTo(zongLB);
        }];
        self.zongPriceLB.textColor = tThreeColor;
        self.zongPriceLB.font = kFont(12);
        self.zongPriceLB.text = @"0";
        
        UILabel *noteLB = [[UILabel alloc]init];
        [self.view addSubview:noteLB];
        [noteLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(20);
            make.right.equalTo(-20);
            make.top.equalTo(contentView.mas_bottom).offset(20);
        }];
        noteLB.textColor = tThreeColor;
        noteLB.numberOfLines = 0;
        noteLB.font = kFont(13);
        noteLB.text = LocalizationKey(@"注：在竞升节点的时候，建议填写上级节点的邀请码。\n如果没有填写，则默认自己为根节点。\n竞升节点每个钱包只能操作一次，请慎重填写。");
        
        UIButton *shenClickBtn = [[UIButton alloc]init];
        [contentView addSubview:shenClickBtn];
        [shenClickBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(0);
            make.centerY.equalTo(shenLB);
            make.height.equalTo(35);
        }];
        [shenClickBtn addTarget:self action:@selector(shenClickBtnAct) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *kuanClickBtn = [[UIButton alloc]init];
           [contentView addSubview:kuanClickBtn];
           [kuanClickBtn mas_makeConstraints:^(MASConstraintMaker *make) {
               make.left.right.equalTo(0);
               make.centerY.equalTo(kuanLB);
               make.height.equalTo(35);
           }];
           [kuanClickBtn addTarget:self action:@selector(kuanClickBtnAct) forControlEvents:UIControlEventTouchUpInside];
    }
}

- (void)shenClickBtnAct{
    MyNodeShenVC *VC = [[MyNodeShenVC alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
}

- (void)kuanClickBtnAct{
    MyNodeKuanVC *VC = [[MyNodeKuanVC alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
}

- (void)jinShengBtnAct{
   
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
